home *** CD-ROM | disk | FTP | other *** search
- %
- % "fact.t" computes the factorial of a number
- % using recursion
- %
- % Sample program for the T Interpreter by:
- %
- % Stephen R. Schmitt
- % 962 Depot Road
- % Boxborough, MA 01719
- %
-
- var number : int
-
- program
-
- prompt "Enter an integer > 0:"
- get number
- put ""
- put "N = ", number
- put "N! = ", factorial( number )
-
- end program
-
- function factorial( n : int ) : int
-
- assert n <= 12 % avoid numerical overflow
-
- if n > 0 then
-
- n := n * factorial( n - 1 )
-
- else
-
- n := 1
-
- end if
-
- return n
-
- end function